package com.websocketdemo.demo.WebSocket.web.Controller;

import com.alibaba.fastjson.JSONObject;
import com.websocketdemo.demo.WebSocket.entity.UserEntity;
import com.websocketdemo.demo.WebSocket.service.inter.Ituser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController
@RequestMapping("rest")
public class restController {
    @Autowired
    Ituser ituser;
    @RequestMapping("login")
    public JSONObject login(@RequestBody UserEntity u){
        System.out.println(u);
       String userEntity= ituser.findUser(u.getUsername());
        System.out.println(userEntity);
        JSONObject jsonObject = new JSONObject();
        if(userEntity!=null&&u.getPassword().equals(userEntity))
        jsonObject.put("massage","1");
        else
            jsonObject.put("massage","2");
        return jsonObject;
    }
    @RequestMapping("register")
    public JSONObject register(@RequestBody UserEntity u){
//    ituser.insertuser(u);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("massage","1");
        return jsonObject;
    }
}
